home *** CD-ROM | disk | FTP | other *** search
- {$A-,B-,D-,E+,F-,I-,L-,N+,O-,R-,S-,V-}
- unit BFLOAT;
- (*
- MicroSoft Binary Float to IEEE format Conversion
- Copyright (c) 1989 J.P. Ritchey
- Version 1.0
-
- This software is released to the public domain. Though
- tested, there could be some errors. Any reports of bugs
- discovered would be appreciated. Send reports to
- Pat Ritchey Compuserve ID 72537,2420
- *)
- interface
-
- type
- bfloat4 = record
- { M'Soft single precision }
- mantissa : array[5..7] of byte;
- exponent : byte;
- end;
-
- Bfloat8 = record
- { M'Soft double precision }
- mantissa : array[1..7] of byte;
- exponent : byte;
- end;
-
-
- Function Bfloat4toExtended(d : bfloat4) : extended;
- Function Bfloat8toExtended(d : Bfloat8): extended;
-
- { These routines will convert a MicroSoft Binary Floating point
- number to IEEE extended format. The extended is large enough
- to store any M'Soft single or double number, so no over/underflow
- problems are encountered. The Mantissa of an extended is large enough
- to hold a BFloatx mantissa, so no truncation is required.
-
- The result can be returned to TP single and double variables and
- TP will handle the conversion. Note that Over/Underflow can occur
- with these types. }
-
- Function HexExt(ep:extended) : string;
-
- { A routine to return the hex representation of an IEEE extended variable
- Left in from debugging, you may find it useful }
-
- Function ExtendedtoBfloat4(ep : extended; var b : bfloat4) : boolean;
- Function ExtendedtoBfloat8(ep : extended; var b : Bfloat8) : boolean;
-
- { These routines are the reverse of the above, that is they convert
- TP extended => M'Soft format. You can use TP singles and doubles
- as the first parameter and TP will do the conversion to extended
- for you.
-
- The Function result returns True if the conversion was succesful,
- and False if not (because of overflow).
-
- Since an extended can have an exponent that will not fit
- in the M'Soft format Over/Underflow is handled in the following
- manner:
- Overflow: Set the Bfloatx to 0 and return a False result.
- Underflow: Set the BFloatx to 0 and return a True Result.
-
- No rounding is done on the mantissa. It is simply truncated to
- fit. }
-
-
- Function BFloat4toReal(b:bfloat4) : Real;
- Function BFloat8toReal(b:bfloat8) : Real;
-
- { These routines will convert a MicroSoft Binary Floating point
- number to Turbo real format. The real is large enough
- to store any M'Soft single or double Exponent, so no over/underflow
- problems are encountered. The Mantissa of an real is large enough
- to hold a BFloat4 mantissa, so no truncation is required. The
- BFloat8 mantissa is truncated (from 7 bytes to 5 bytes) }
-
- Function RealtoBFloat4(rp: real; var b:bfloat4) : Boolean;
- Function RealtoBFloat8(rp : real; var b:bfloat8) : Boolean;
-
- { These routines do the reverse of the above. No Over/Underflow can
- occur, but truncation of the mantissa can occur
- when converting Real to Bfloat4 (5 bytes to 3 bytes).
-
- The function always returns True, and is structured this way to
- function similar to the IEEE formats }
-
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- The Public (Software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. The P(s)L cannot de-
- bug programs over the telephone.
-
- Disks in the P(s)L are updated monthly, so if you did not get
- this disk directly from the P(s)L, you should be aware that
- the files in this set may no longer be the current versions.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 1,800+ disks in the library, call or write
-
- The Public (Software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
- (713) 665-7017
-